Blob fields (Binary)
Blob fields (Binary Large OBject) used in Paradox tables to store any kind of data,
such as word documents, pictures, wave files, etc. It is like a memo, (Virtualy there
is no limit in size). Below example illustrates how to store file in a Blob field
(Blob field in this example is called "Data"):
1. Loading files into Blob fields:
procedure TForm1.btLoadClick(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
try
Table1.Append;
(*** Save file name in a string field called "File" ***)
Table1.FieldByName('File').AsString:=
ExtractFileName(OpenDialog1.FileName);
(*** Load file contents into Blob field ***)
TBlobField(Table1.FieldByName('Data')).LoadFromFile(OpenDialog1.FileName);
Table1.Post;
except
on E: Exception do
Table1.Cancel;
end; // try
end; // if OpenDialog
end;
2. Extracting files from Blob fields:
Next example illustrates how to read file from a Blob field:
- Add ShellApi in Uses clause:
procedure TForm1.btOpenClick(Sender: TObject);
var
FileName: string;
begin
FileName:= Table1.FieldByName('File').AsString;
(*** Save Blob field contents into disk ***)
TBlobField(Table1.FieldByName('Data')).SaveToFile(FileName);
(*** Open the file ***)
ShellExecute(handle, 'open',
PChar(FileName), nil, nil, sw_Normal);
end;